/**
 * 
 */
package SRTPlanner;

import java.util.ArrayList;
import java.util.HashSet;

import simulation.ConfigGraph;
import simulation.Configuration;
import simulation.Simulation;

/**
 * @author aclayton
 *
 */
public class SRT {
	private final int numRandomConfig = 10;
	
	private Simulation sim;
	private HashSet<ConfigGraph> graphs;
	private SimpleLocalPlanner lp; 
	private ConfigGraph completeGraph;
	
	public SRT(Simulation simulation){
		sim = simulation;
		graphs = new HashSet<ConfigGraph>();
		lp = new SimpleLocalPlanner(sim.getMap());
		completeGraph = new ConfigGraph(sim.getMap().getBoundingBox());
	}
	
	public void addGraph(ConfigGraph newGraph){
		graphs.add(newGraph);
		completeGraph.addGraph(newGraph);
	}
	
	public void runSRT(){
		for(ConfigGraph g : graphs){
			HashSet<ConfigGraph> neighboringGraphs = new HashSet<ConfigGraph>();
			
			for(ConfigGraph n : graphs){
				if(g != n && g.getBoundingBox().adjacentRect(n.getBoundingBox()))
					neighboringGraphs.add(n);
			}
			
			for(ConfigGraph neighborGraph : neighboringGraphs){
				HashSet<Configuration> randomlyChoosenConfigs  = g.getRandomConfigurationSet(100);
				for(Configuration randomConfig : randomlyChoosenConfigs){
					Configuration closest = neighborGraph.getClosestConfiguration(randomConfig);
					if(lp.existsPath(randomConfig, closest))
						completeGraph.addEdge(randomConfig, closest);
						
				}
			}
		}
	}

	public ConfigGraph getSRTGraph() {
		return completeGraph;
	}
}
